<!--#include file="../nav/admin_top.php" -->
<div class="titleDiv">
	<div class="titleCaption">
		<span class="captionSpan">订单审核</span>
	</div>
</div>
<?PHP
$orderstatus = '1';
?>
<!--#include file="../nav_menu/order_begin.php" -->
 
<div class="menuBg">
	<a class="tongguo" href="javascript:void(0)" onclick="fnPiOptOk()">批量审核通过</a> 
	<a class="chexiao" href="javascript:void(0)" onclick="fnPiOptUnOk()">批量撤销审核</a> 
  <div style="clear:both"></div>
</div>
<div style="margin-bottom:15px">
	搜索：
	<select id="senddate" class="textBox"  onChange="fnSearchDate()" style="margin-right:5px;">
		<option value="0" selected="selected">所有下单日期</option>
		<option value="1">今天</option> 
		<option value="2">本周</option> 
		<option value="3">本月</option> 
		<option value="">自定义时间段</option> 
	</select>
	<span id="s_date_div" style="display:none;margin:5px auto;">
		从 <input type="text" class="textBoxDate" id="b_date" value=""   maxlength="10" />
		<input id="b_date_slt" class="btnicon_calendar" type="button">
		到
		<input type="text" class="textBoxDate" id="e_date" value=""   maxlength="10" />
		<input id="e_date_slt" class="btnicon_calendar" type="button">
	</span>	
	<select id="slt_rec_date" class="textBox"  onChange="fnRecDate()" style="margin-right:5px;">
		<option value="0" selected="selected">所有配送日期</option>
		<option value="1">今天</option> 
		<option value="2">明天</option> 
		<option value="3">本周</option> 
		<option value="4">本月</option> 
		<option value="">自定义时间段</option> 
	</select>
	<span id="s_slt_rec_date" style="display:none;margin:5px auto;">
		从 <input type="text" class="textBoxDate" id="rec_bdate" value=""   maxlength="10" />
		<input id="rec_bdate_slt" class="btnicon_calendar" type="button">
		到
		<input type="text" class="textBoxDate" id="rec_edate" value=""   maxlength="10" />
		<input id="rec_edate_slt" class="btnicon_calendar" type="button">
	</span>	
	<select id="sendtime" class="textBox"  onChange="fnSearchs()" style="margin-right:5px;">
		<option value="" selected="selected">所有配送时间段</option>
		<?PHP
		$sendtime = factory::module('list')->getlist('sendtime');
		foreach($sendtime as $v){
			echo '<option value="'.$v['id'].'">'.$v['val'].'</option>';
		}
		?>
	</select>
	
	<span style="margin-left:40px;">
		<input type="text" maxlength="12" id="keywords" class="searchs" /> 
		<input type="button"  onclick="fnSearchs()" value="查询"  />  	
	</span>	
</div> 
<div id="grids"></div> 

<script type="text/javascript">
var url_sh = '/admin_order/sh_complete';
var url_unsh = '/admin_order/sh_uncomplete';



function fnPiOptOk(){
	var selected = grids.getSelect();
	if(selected.length == 0){ 
		alert('请至少选择一条记录！');
		return false;
	}
	var slts = [];
	for(var i=0;i<selected.length; i++){
		slts.push(selected[i].id); 
	}
	fnConfirm({
		str:'确定批量审核通过？',
		func_true:function(){
			$('button').attr('disabled','disabled');
			$.post(
				url_sh,
				{
					ids:JSON.encode(slts)
				},
				function(e){
					var ok = errorHandler(e);
					if(ok && ok.success=='1'){
						grids.reload();
						fnLoadOptNum();
					}
					$('button').attr('disabled','');
				}
			);
		}
	});
}

function fnPiOptUnOk(){
	var selected = grids.getSelect();
	if(selected.length == 0){ 
		alert('请至少选择一条记录！');
		return false;
	}
	var slts = [];
	for(var i=0;i<selected.length; i++){
		slts.push(selected[i].id); 
	}
	fnConfirm({
		str:'确定批量撤销审核？',
		func_true:function(){
			$('button').attr('disabled','disabled');
			$.post(
				url_unsh,
				{
					ids:JSON.encode(slts)
				},
				function(e){
					var ok = errorHandler(e);
					if(ok && ok.success=='1'){
						grids.reload();
						fnLoadOptNum();
					}
					$('button').attr('disabled','');
				}
			);
		}
	});
}


/* 设置 */
function fnOk(NId){
	fnConfirm({
		str:'确认审核通过？',
		func_true:function(){
			$('button').attr('disabled','disabled');
			$.post(
				url_sh,
				{
					ids:JSON.encode([NId])
				},
				function(e){
					var ok = errorHandler(e);
					if(ok && ok.success=='1'){
						grids.reload();
						fnLoadOptNum();
					}
					$('button').attr('disabled','');
				}
			);
		}
	}); 
}
function fnUnOk(NId){
	fnConfirm({
		str:'确认撤销审核？',
		func_true:function(){
			$('button').attr('disabled','disabled');
			$.post(
				url_unsh,
				{
					ids:JSON.encode([NId])
				},
				function(e){
					var ok = errorHandler(e);
					if(ok && ok.success=='1'){
						grids.reload();
						fnLoadOptNum();
					}
					$('button').attr('disabled','');
				}
			);
		}
	}); 
}





$().ready(function(){
	o2js.build('o2grid');
	grids = new o2Grid({
		bind:'grids', 
		url:url_list,
		singleSelect:false,
		imgpath:'/misc/vendors/o2js/o2grid/image',
		cols:[
			{index:'id',mapping:'a.id', name:'序号', width:35,sortable:false, func:function(val,row_index,column_name,json,R){
				 return  '<span title="ID：'+json.id+'" >'+((R.page - 1)*R.rowNum + (row_index+1))+'</span>';
			}}, 
			{index:'code',mapping:'a.code', name:'订单编号', width:110,align:"center",func:function(val,row_index,column_name,json,R){
					return ' <a href="'+url_view+'?id='+json.id+'" target="_blank"  >'+val+'</a>';
			}
			},
			{index:'created',mapping:'a.created', name:'下单日期', width:120 ,align:"center"
			},
			{index:'rec_date',mapping:'a.rec_date', name:'配送日期', width:70 ,align:"center",func:function(val,row_index,column_name,json,R){
					return val+'<br>'+json.sendtime;
			}
			},
			{index:'price_total',mapping:'a.price_total', name:'订单总额', width:65 ,align:"right",func:function(val,row_index,column_name,json,R){
					return '￥'+val;
			}
			},
			{index:'user_name',mapping:'b.name', name:'会员', width:75  ,func:function(val,row_index,column_name,json,R){
					return '('+json.username+')'+val;
			}		
			},
			{index:'status',mapping:'a.status', name:'订单状态', width:75 ,func:function(val,row_index,column_name,json,R){
					if(val == '-2'){
						return  '<span class="gray">系统取消</span>';
					}else if(val == '-1'){
						return  '<span class="gray">用户取消</span>';
					}else if(val == '0'){
						return  '<span class="red">未支付</span>';
					}else if(val == '1'){
						return  '<span class="red">待审核</span>';
					}else if(val == '2'){
						return  '<span class="red">已审核，待生产</span>';
					}else if(val == '3'){
						return  '<span class="red">已生产，待配送</span>';
					}else{
						return '<span class="green">已配送</span>';
					}
			}
			},
			{index:'id',mapping:'a.id', name:'操作'	, width:170,sortable:false,func:function(val,row_index,column_name,json,R){
					//var s = ' <a href="'+url_view+'?id='+json.id+'" target="_blank" style="margin-right:5px;" >详情</a>';
					var s='';
					if(json.status == '1'){
						s += ' <a href="javascript:void(0)"  onclick="fnModify('+json.id+')"   >改配送日期</a>';
						s += ' &nbsp;<a href="/admin_order/modify?id='+json.id+'"  target="_blank" >修改</a>';
						s += ' &nbsp;<a href="javascript:void(0)"  onclick="fnOk('+json.id+')"   >审核通过</a>';
					}
					if(json.status == '2'){
						s += ' <a href="javascript:void(0)"  onclick="fnUnOk('+json.id+')"  >撤销审核</a>';
					}
					return s;
					
				}
			}
		]
	});
	$('#keywords').keypress(function(e){
		if(e.keyCode==13||e.keyCode==10){
			fnSearchs();
		}
	});
	fnSearchs();	 
});



function fnModify(id){
	ymPrompt.close();
	ymPrompt.win({
		title:'修改配送日期',
		fixPosition:true,
		maxBtn:true,
		width: 500, 
		height: 350,
		iframe:{
			src:'/admin_order/recdate_modify?id='+id+'&endfunc=fnModifyInfoEnd'
		}
	}); 
} 
function fnModifyInfoEnd(){
	grids.reload();
}
</script> 
<!--#include file="../nav_menu/order_end.php" -->
<!--#include file="../nav/admin_bottom.php" -->